﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ScanDevConsole
{
    public class CommonLamp : System.Windows.Forms.Button
    {
        public string[] namesOnOff;
        private bool ison = false;
        public bool isOn
        {
            get { return ison; }
            set
            {
                ison = value;
                if (ison)
                {
                    BackColor = System.Drawing.Color.LightGreen;
                    if(namesOnOff!=null && namesOnOff.Length >= 2)
                    {
                        Text = namesOnOff[1];
                    }
                }
                else
                {
                    BackColor = System.Drawing.Color.DarkRed;
                    if (namesOnOff != null && namesOnOff.Length >= 2)
                    {
                        Text = namesOnOff[0];
                    }
                }
            }
        }
        public CommonLamp() : base()
        {
            FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            FlatAppearance.BorderSize = 0;
            //Location = new System.Drawing.Point(0, 0);
            //Size = new System.Drawing.Size(80, 80);
            System.Drawing.Drawing2D.GraphicsPath path1 = new System.Drawing.Drawing2D.GraphicsPath();
            path1.AddEllipse(ClientRectangle);
            Region = new System.Drawing.Region(path1);
            isOn = false;

            Resize += new System.EventHandler(onResized);
            //MouseDown += new System.Windows.Forms.MouseEventHandler(onBtnDown);
            //MouseUp += new System.Windows.Forms.MouseEventHandler(onBtnUp);
        }

        private void onResized(object sender, EventArgs e)
        {
            System.Drawing.Drawing2D.GraphicsPath path1 = new System.Drawing.Drawing2D.GraphicsPath();
            path1.AddEllipse(ClientRectangle);
            Region = new System.Drawing.Region(path1);
        }


        private void onBtnDown(object sender, MouseEventArgs e)
        {
            isOn = !isOn;
            if (isOn)
            {
                BackColor = System.Drawing.Color.LightGreen;
            }
            else
            {
                BackColor = System.Drawing.Color.DarkRed;
            }
        }

        private void onBtnUp(object sender, MouseEventArgs e)
        {

        }
    }
}
